const user = {
	state: {
		userInfo: JSON.parse(localStorage.getItem('userInfo') == "" ? null : localStorage.getItem('userInfo')),
		token:localStorage.getItem('token')||''
	},

	mutations: {
		SET_userInfo: (state, userInfo) => {
			state.userInfo = userInfo
		},
		REMOVE_token: (state, token) => {
			state.token = token
		},
	},

	actions: { //异步操作mutation
		// 登录
		set_Login_info({
			commit
		}, userInfo) {
			localStorage.setItem('userInfo', JSON.stringify(userInfo));
			localStorage.setItem('token', userInfo.token);
			commit('SET_userInfo', userInfo)
		},
		//清除 token
		resetToken({ commit }) {
			return new Promise(resolve => {
			  localStorage.removeItem('token')
			  commit('REMOVE_token','')
			  resolve()
			})
		}
	}
}

export default{
	namespaced: true,
	...user
}